<template>
  <q-page class="full-height">
    <iframe
      frameborder="0"
      @load="loading = false"
      :src="url"
      class="fit absolute"
    ></iframe>
    <q-inner-loading
      :showing="loading"
      label="正在加载..."
      label-class="text-primary"
      label-style="font-size: 1.1em"
    />
  </q-page>
</template>

<script setup lang="ts">
import { ref, onActivated, onDeactivated } from 'vue';
import { onBeforeRouteLeave, onBeforeRouteUpdate } from 'vue-router';
interface Props {
  // 外链地址
  url: string;
}
withDefaults(defineProps<Props>(), {});
const loading = ref(true);
let setTime: NodeJS.Timeout;
onBeforeRouteUpdate(() => {
  loading.value = true;
  setTime = setTimeout(() => {
    loading.value = false;
  }, 5000);
});

onBeforeRouteLeave(() => {
  loading.value = false;
  clearTimeout(setTime);
});
onActivated(() => {
  loading.value = true;
  setTime = setTimeout(() => {
    loading.value = false;
  }, 5000);
});
onDeactivated(() => {
  loading.value = false;
  clearTimeout(setTime);
});
</script>

<style lang="scss" scoped></style>
